<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html
 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html
 xmlns="http://www.w3.org/1999/xhtml"
 xmlns:xh="http://www.w3.org/1999/xhtml"
 xmlns:xf="http://www.w3.org/2002/xforms"
 xmlns:ev="http://www.w3.org/2001/xml-events"
 xmlns:js="http://www.formsplayer.com/inlineScript"
>
	<head>
		<title>Stem</title>

		<script type="text/javascript" src="gadgets/common/scripts/events.js">/**/</script>

		<script type="text/javascript" src="gadgets/common/scripts/geometry.js">/**/</script>

		<script type="text/javascript" src="gadgets/common/scripts/timers.js">/**/</script>

		<script type="text/javascript" src="gadgets/common/scripts/base64.js">/**/</script>

		<script type="text/javascript" src="gadgets/common/scripts/dragdrop.js">/**/</script>

		<script type="text/javascript" src="gadgets/common/scripts/style.js">/**/</script>

		<link rel="stylesheet" href="hubbub.css" type="text/css" media="screen" />

		<link rel="stylesheet" href="stem.css" type="text/css" media="screen" />

		<xf:model id="mdl-gadgets">
			<xf:instance id="inst-hubbub" src="hubbub-default.xhtml" />

			<xf:submission id="sbm-hubbub-load" method="get" resource="cookie:hubbub-0.5/hubbub.xhtml" replace="instance" instance="inst-hubbub" />

			<xf:submission id="sbm-hubbub-save" method="put" resource="cookie:hubbub-0.5/hubbub.xhtml" replace="none" ref="instance('inst-hubbub')" mode="synchronous" />

			<xf:submission id="sbm-authorisation-friendfeed" method="get" resource="http://friendfeed.com/api/validate" replace="none" serialize="false" mode="synchronous" authenticate="false">
				<xf:header>
					<xf:name value="'Authorization'" />
					<xf:value value="instance('inst-hubbub')/xh:head/xh:meta[@property = 'friendfeed:authorisation']/@content" />
				</xf:header>
			</xf:submission>

			<xf:submission id="sbm-authorisation-twitter" method="get" resource="http://twitter.com/account/verify_credentials.xml" replace="none" serialize="false" mode="synchronous" authenticate="false">
				<xf:header>
					<xf:name value="'Authorization'" />
					<xf:value value="instance('inst-hubbub')/xh:head/xh:meta[@property = 'twitter:authorisation']/@content" />
				</xf:header>
			</xf:submission>

			<xf:instance id="inst-authorisation">
				<authorisation xmlns="">
					<friendfeed>
						<nickname />
						<apikey />
						<status>
							<unauthorised>true</unauthorised>
							<authorised>false</authorised>
						</status>
					</friendfeed>
					<twitter>
						<username />
						<password />
						<status>
							<unauthorised>true</unauthorised>
							<authorised>false</authorised>
						</status>
					</twitter>
				</authorisation>
			</xf:instance>

			<xf:bind nodeset="instance('inst-authorisation')">
				<xf:bind nodeset="*/status/unauthorised" calculate="if(../authorised = 'false', 'true', 'false')" />

				<xf:bind nodeset="*/status/*" relevant=". = 'true'" />
			</xf:bind>

			<xf:instance id="inst-messages">
				<messages xmlns="">
					<friendfeedapikey>&lt;a href="http://friendfeed.com/remotekey" target="_blank"&gt;What is my FriendFeed remote API key?&lt;/a&gt;</friendfeedapikey>
					<friendfeedauthorisationerror relevant="false">FriendFeed authorization error</friendfeedauthorisationerror>
					<twitterauthorisationerror relevant="false">Twitter authorization error</twitterauthorisationerror>
				</messages>
			</xf:instance>

			<xf:bind nodeset="instance('inst-messages')">
				<xf:bind nodeset="friendfeedapikey" relevant="../friendfeedauthorisationerror/@relevant = 'false'" />

				<xf:bind nodeset="friendfeedauthorisationerror" relevant="@relevant = 'true'" />

				<xf:bind nodeset="twitterauthorisationerror" relevant="@relevant = 'true'" />
			</xf:bind>

			<xf:instance id="inst-friends">
				<friends xmlns=""></friends>
			</xf:instance>

			<xf:submission id="sbm-friends-friendfeed" method="get" replace="instance" instance="inst-friends" serialize="false">
				<xf:resource value="concat('http://friendfeed.com/api/user/', instance('inst-authorisation')/friendfeed/nickname, '/profile?format=xml')" />

				<xf:header>
					<xf:name value="'Authorization'" />
					<xf:value value="instance('inst-hubbub')/xh:head/xh:meta[@property = 'friendfeed:authorisation']/@content" />
				</xf:header>
			</xf:submission>

			<xf:instance id="inst-templates" src="templates.xml" />

			<xf:instance id="inst-iterators">
				<iterators xmlns="">
					<hubs />
				</iterators>
			</xf:instance>

			<xf:instance id="inst-geometry">
				<geometry xmlns="">
					<x />
					<y />
					<width />
					<height />
				</geometry>
			</xf:instance>

			<xf:instance id="inst-scripts">
				<scripts xmlns="">
					<retval />
				</scripts>
			</xf:instance>

			<xf:bind id="script-retval" nodeset="instance('inst-scripts')/retval" />

			<xf:instance id="inst-invoke">
				<invoke xmlns="" />
			</xf:instance>

			<xf:instance id="inst-ready">
				<ready xmlns="">true</ready>
			</xf:instance>

			<xf:instance id="inst-show">
				<show xmlns="">true</show>
			</xf:instance>

			<xf:instance id="inst-hub-base">
				<hub-base xmlns="" />
			</xf:instance>

			<xf:instance id="inst-delete-hub">
				<delete-hub xmlns="">
					<pending />
					<processing />
				</delete-hub>
			</xf:instance>

			<xf:action ev:event="xforms-ready">
				<xf:setvalue bind="script-retval" value="js:EVENTS_initUpdateHandler()" />

				<xf:setvalue bind="script-retval" value="js:EVENTS_initInvokeHandler()" />

				<xf:action if="instance('inst-ready') = 'true'">
					<xf:setvalue ref="instance('inst-ready')" value="'false'" />

					<xf:setvalue bind="script-retval" value="js:EVENTS_send('backplane-ready')" />
				</xf:action>
			</xf:action>

			<xf:action ev:event="backplane-update">
				<xf:action if="instance('inst-show') = 'true'">
					<xf:setvalue ref="instance('inst-show')" value="'false'" />

					<xf:setvalue bind="script-retval" value="js:EVENTS_send('backplane-show')" />

					<xf:setvalue ref="instance('inst-geometry')/x" value="js:GEOMETRY_getXPos('configure-button')" />

					<xf:setvalue ref="instance('inst-geometry')/width" value="js:GEOMETRY_getWidth('configure-button')" />

					<xf:setvalue bind="script-retval" value="js:EVENTS_send('backplane-open', concat('s,', floor(number(instance('inst-geometry')/x) + number(instance('inst-geometry')/width) div 2 - 9), ',c|help|start'))" />
				</xf:action>

				<xf:send submission="sbm-hubbub-load" />
			</xf:action>

			<xf:action ev:observer="sbm-hubbub-load" ev:event="xforms-submit-error">
				<xf:dispatch name="force-newhub-position-absolute" target="mdl-gadgets" />
			</xf:action>

			<xf:action ev:observer="sbm-hubbub-load" ev:event="xforms-submit-done">
				<xf:setvalue ref="instance('inst-authorisation')/friendfeed/nickname" value="substring-before(js:BASE64_decode(substring-after(instance('inst-hubbub')/xh:head/xh:meta[@property = 'friendfeed:authorisation']/@content, 'Basic ')), ':')" />

				<xf:setvalue ref="instance('inst-authorisation')/friendfeed/apikey" value="substring-after(js:BASE64_decode(substring-after(instance('inst-hubbub')/xh:head/xh:meta[@property = 'friendfeed:authorisation']/@content, 'Basic ')), ':')" />

				<xf:send if="instance('inst-authorisation')/friendfeed/nickname != '' and instance('inst-authorisation')/friendfeed/apikey != ''" submission="sbm-authorisation-friendfeed" />

				<xf:setvalue ref="instance('inst-authorisation')/twitter/username" value="substring-before(js:BASE64_decode(substring-after(instance('inst-hubbub')/xh:head/xh:meta[@property = 'twitter:authorisation']/@content, 'Basic ')), ':')" />

				<xf:setvalue ref="instance('inst-authorisation')/twitter/password" value="substring-after(js:BASE64_decode(substring-after(instance('inst-hubbub')/xh:head/xh:meta[@property = 'twitter:authorisation']/@content, 'Basic ')), ':')" />

				<xf:send if="instance('inst-authorisation')/twitter/username != '' and instance('inst-authorisation')/twitter/password != ''" submission="sbm-authorisation-twitter" />

				<xf:setvalue ref="instance('inst-iterators')/hubs" value="1" />

				<xf:dispatch name="hubbub-restore-hubs-iteration" target="mdl-gadgets" />
			</xf:action>

			<xf:action ev:event="hubbub-restore-hubs-iteration">
				<xf:setvalue bind="script-retval" value="js:TIMERS_destroyTimer('hubbub-restore-hubs-iteration')" />

				<xf:dispatch if="count(instance('inst-hubbub')/xh:body/xh:div[@id = 'hubs']/*[@typeof = 'hubbub:hub']) = 0" name="force-newhub-position-absolute" target="mdl-gadgets" />

				<xf:action if="number(instance('inst-iterators')/hubs) &lt;= count(instance('inst-hubbub')/xh:body/xh:div[@id = 'hubs']/*[@typeof = 'hubbub:hub'])">
					<xf:setvalue bind="script-retval" value="js:EVENTS_send('backplane-open', concat('s,', 95 + (number(instance('inst-iterators')/hubs) - 1) * 120, ',c|hub|', substring-after(instance('inst-hubbub')/xh:body/xh:div[@id = 'hubs']/*[contains(@typeof, 'hubbub:hub')][number(instance('inst-iterators')/hubs)]/@id, '-')))" />

					<xf:setvalue ref="instance('inst-iterators')/hubs" value="number(.) + 1" />

					<xf:setvalue bind="script-retval" value="js:TIMERS_setTimer(2000, 'single', 'mdl-gadgets', 'hubbub-restore-hubs-iteration', 'hubbub-restore-hubs-iteration')" />
				</xf:action>
			</xf:action>

			<xf:action ev:observer="sbm-authorisation-friendfeed" ev:event="xforms-submit">
				<xf:setvalue ref="instance('inst-hubbub')/xh:head/xh:meta[@property = 'friendfeed:authorisation']/@content" value="concat('Basic ', js:BASE64_encode(concat(instance('inst-authorisation')/friendfeed/nickname, ':', instance('inst-authorisation')/friendfeed/apikey)))" />
			</xf:action>

			<xf:action ev:observer="sbm-authorisation-friendfeed" ev:event="xforms-submit-error">
				<xf:setvalue ref="instance('inst-messages')/friendfeedauthorisationerror/@relevant" value="'true'" />
			</xf:action>

			<xf:action ev:observer="sbm-authorisation-friendfeed" ev:event="xforms-submit-done">
				<xf:setvalue ref="instance('inst-messages')/friendfeedauthorisationerror/@relevant" value="'false'" />

				<xf:setvalue ref="instance('inst-authorisation')/friendfeed/status/authorised" value="'true'" />

				<xf:send submission="sbm-hubbub-save" />

				<xf:setvalue bind="script-retval" value="js:EVENTS_send('backplane-set-authorisation', concat('friendfeed|', instance('inst-hubbub')/xh:head/xh:meta[@property = 'friendfeed:authorisation']/@content))" />

				<xf:action if="count(instance('inst-hubbub')/xh:body/xh:div[@id = 'hubs']/xh:div[@typeof = 'hubbub:hub']) = 0">
					<xf:setvalue ref="instance('inst-geometry')/x" value="js:GEOMETRY_getXPos('newhub-button')" />

					<xf:setvalue ref="instance('inst-geometry')/width" value="js:GEOMETRY_getWidth('newhub-button')" />

					<xf:setvalue bind="script-retval" value="js:EVENTS_send('backplane-open', concat('s,', floor(8 + number(instance('inst-geometry')/x) + number(instance('inst-geometry')/width) div 2 - 9), ',c|help|newhub'))" />
				</xf:action>
			</xf:action>

			<xf:action ev:observer="sbm-authorisation-twitter" ev:event="xforms-submit">
				<xf:setvalue ref="instance('inst-hubbub')/xh:head/xh:meta[@property = 'twitter:authorisation']/@content" value="concat('Basic ', js:BASE64_encode(concat(instance('inst-authorisation')/twitter/username, ':', instance('inst-authorisation')/twitter/password)))" />
			</xf:action>

			<xf:action ev:observer="sbm-authorisation-twitter" ev:event="xforms-submit-error">
				<xf:setvalue ref="instance('inst-messages')/twitterauthorisationerror/@relevant" value="'true'" />
			</xf:action>

			<xf:action ev:observer="sbm-authorisation-twitter" ev:event="xforms-submit-done">
				<xf:setvalue ref="instance('inst-messages')/twitterauthorisationerror/@relevant" value="'false'" />

				<xf:setvalue ref="instance('inst-authorisation')/twitter/status/authorised" value="'true'" />

				<xf:send submission="sbm-hubbub-save" />

				<xf:setvalue bind="script-retval" value="js:EVENTS_send('backplane-set-authorisation', concat('twitter|', instance('inst-hubbub')/xh:head/xh:meta[@property = 'twitter:authorisation']/@content))" />
			</xf:action>

			<xf:action ev:observer="sbm-friends-friendfeed" ev:event="xforms-submit">
				<xf:toggle case="view-friends-loading" />
			</xf:action>

			<xf:action ev:observer="sbm-friends-friendfeed" ev:event="xforms-submit-error">
				<xf:toggle case="view-friends-failed" />
			</xf:action>

			<xf:action ev:observer="sbm-friends-friendfeed" ev:event="xforms-submit-done">
				<xf:toggle case="view-friends-loaded" />
			</xf:action>

			<xf:action ev:event="hubbub-new-hub">
				<xf:insert
				 origin="instance('inst-templates')/xh:div[@id = 'hub']"
				 context="instance('inst-hubbub')/xh:body/xh:div[@id = 'hubs']"
				 nodeset="xh:div"
				 at="count(../xh:div)"
				 position="after"
				/>

				<xf:setvalue
				 ref="instance('inst-hubbub')/xh:body/xh:div[@id = 'hubs']/xh:div[@id = 'hub']/*[@property = 'hubbub:name']"
				 value="concat('Hub ', if(count(instance('inst-hubbub')/xh:body/xh:div[@id = 'hubs']/*[contains(@typeof, 'hubbub:hub')]) &gt; 1, number(substring-after(instance('inst-hubbub')/xh:body/xh:div[@id = 'hubs']/*[contains(@typeof, 'hubbub:hub')][last() - 1]/@id, '-')) + 1, '1'))"
				/>

				<xf:setvalue
				 ref="instance('inst-hubbub')/xh:body/xh:div[@id = 'hubs']/xh:div[@id = 'hub']/@id"
				 value="concat('hub-', substring-after(../*[@property = 'hubbub:name'], ' '))"
				/>

				<xf:setvalue bind="script-retval" value="js:EVENTS_send('backplane-open', concat('s,', 95 + (count(instance('inst-hubbub')/xh:body/xh:div[@id = 'hubs']/xh:div[@typeof = 'hubbub:hub']) - 1) * 120, ',c|hub|', substring-after(instance('inst-hubbub')/xh:body/xh:div[@id = 'hubs']/*[contains(@typeof, 'hubbub:hub')][last()]/@id, '-')))" />

				<xf:send submission="sbm-hubbub-save" />
			</xf:action>

			<xf:action ev:event="backplane-invoke">
				<xf:dispatch if="instance('inst-invoke') = 'hide'" name="hubbub-hide" target="mdl-gadgets" />
			</xf:action>

			<xf:action ev:event="hubbub-hide">
				<xf:toggle case="view-restore-hubbub" />

				<xf:toggle case="view-friends-show" />

				<xf:toggle case="view-configure-show" />

				<xf:toggle case="view-config-hidden" />

				<xf:setvalue bind="script-retval" value="js:EVENTS_send('backplane-set-size', '|26')" />

				<xf:setvalue bind="script-retval" value="js:EVENTS_send('backplane-hide-all', 'false')" />
			</xf:action>

			<xf:action ev:event="force-newhub-position-absolute">
				<xf:setvalue bind="script-retval" value="js:STYLE_set('newhub-button-container', 'position', 'absolute')" />

				<xf:setvalue bind="script-retval" value="js:STYLE_set('newhub-button-container', 'left', '170px')" />

				<xf:setvalue bind="script-retval" value="js:STYLE_set('newhub-button-container', 'bottom', '0px')" />
			</xf:action>

			<xf:action ev:event="force-newhub-position-relative">
				<xf:setvalue bind="script-retval" value="js:STYLE_set('newhub-button-container', 'position', 'relative')" />

				<xf:setvalue bind="script-retval" value="js:STYLE_set('newhub-button-container', 'left', '0px')" />

				<xf:setvalue bind="script-retval" value="js:STYLE_set('newhub-button-container', 'top', '0px')" />
			</xf:action>

			<xf:action ev:event="hubbub-delete-hub" if="instance('inst-delete-hub')/pending != ''">
				<xf:setvalue ref="instance('inst-delete-hub')/processing" value="instance('inst-delete-hub')/pending" />

				<xf:setvalue ref="instance('inst-delete-hub')/pending" value="''" />

				<xf:setvalue bind="script-retval" value="js:TIMERS_destroyTimer('hubbub-delete-hub')" />

				<xf:delete nodeset="instance('inst-hubbub')/xh:body/xh:div[@id = 'hubs']/*[contains(@typeof, 'hubbub:hub')][number(instance('inst-delete-hub')/processing)]" />

				<xf:send submission="sbm-hubbub-save" />
			</xf:action>
		</xf:model>
	</head>

	<body ondragenter="event.returnValue = false;" ondragover="event.returnValue = false;" ondrop="event.returnValue = false;">
		<xf:switch>
			<xf:case id="view-config-hidden"></xf:case>

			<xf:case id="view-config-authorisation">
				<div class="config">
					<span class="roundedcorner_box">
						<div class="roundedcorner_top"><div></div></div>
						<div class="roundedcorner_content">
							<h2>
								<img src="gadgets/friendfeed/icon50.png" alt="FriendFeed" class="service-icon" />

								FriendFeed
							</h2>

							<xf:group ref="instance('inst-authorisation')/friendfeed/status/unauthorised">
								<xf:input ref="../../nickname">
									<xf:label>
										Nickname:
									</xf:label>
								</xf:input>

								<xf:secret ref="../../apikey">
									<xf:label>
										Remote API key:
									</xf:label>

									<xf:send ev:event="DOMActivate" submission="sbm-authorisation-friendfeed" />
								</xf:secret>

								<xf:output class="info message" ref="instance('inst-messages')/friendfeedapikey" />

								<xf:output class="error message" ref="instance('inst-messages')/friendfeedauthorisationerror" />

								<xf:submit submission="sbm-authorisation-friendfeed" appearance="minimal" id="friendfeed-signin">
									<xf:label class="button73">
										Sign in
									</xf:label>
								</xf:submit>
							</xf:group>

							<xf:group ref="instance('inst-authorisation')/friendfeed/status/authorised">
								<p>
									You're signed in as <strong><xf:output ref="../../nickname" /></strong>.
								</p>

								<xf:trigger appearance="minimal" class="link">
									<xf:label>
										Click here to sign in to an alternative account
									</xf:label>

									<xf:action ev:event="DOMActivate">
										<xf:setvalue bind="script-retval" value="js:EVENTS_send('backplane-set-authorisation', 'friendfeed|')" />

										<xf:setvalue ref="instance('inst-authorisation')/friendfeed/status/authorised" value="'false'" />
									</xf:action>
								</xf:trigger>
							</xf:group>
						</div>
						<div class="roundedcorner_bottom"><div></div></div>
					</span>

					<span class="roundedcorner_box">
						<div class="roundedcorner_top"><div></div></div>
						<div class="roundedcorner_content">
							<h2>
								<img src="gadgets/twitter/icon50.png" alt="Twitter" class="service-icon" />

								Twitter
							</h2>

							<xf:group ref="instance('inst-authorisation')/twitter/status/unauthorised">
								<xf:input ref="../../username">
									<xf:label>
										User name:
									</xf:label>
								</xf:input>

								<xf:secret ref="../../password">
									<xf:label>
										Password:
									</xf:label>

									<xf:send ev:event="DOMActivate" submission="sbm-authorisation-twitter" />
								</xf:secret>

								<xf:output class="error message" ref="instance('inst-messages')/twitterauthorisationerror" />

								<xf:submit submission="sbm-authorisation-twitter" appearance="minimal" id="twitter-signin">
									<xf:label class="button73">
										Sign in
									</xf:label>
								</xf:submit>
							</xf:group>

							<xf:group ref="instance('inst-authorisation')/twitter/status/authorised">
								<p>
									You're signed in as <strong><xf:output ref="../../username" /></strong>.
								</p>

								<xf:trigger appearance="minimal" class="link">
									<xf:label>
										Click here to sign in to an alternative account
									</xf:label>

									<xf:action ev:event="DOMActivate">
										<xf:setvalue bind="script-retval" value="js:EVENTS_send('backplane-set-authorisation', 'twitter|')" />

										<xf:setvalue ref="instance('inst-authorisation')/twitter/status/authorised" value="'false'" />
									</xf:action>
								</xf:trigger>
							</xf:group>
						</div>
						<div class="roundedcorner_bottom"><div></div></div>
					</span>
				</div>
			</xf:case>

			<xf:case id="view-config-friends">
				<div class="friends">
					<h2>
						<img src="gadgets/friendfeed/icon50.png" alt="FriendFeed" class="service-icon" />

						FriendFeed Palette
					</h2>

					<xf:switch>
						<xf:case id="view-friends-loading">
							<!--
								TODO: Some kind of loading animation here?
							-->
						</xf:case>

						<xf:case id="view-friends-failed">
							<p>
								FriendFeed request failed. Try again?
							</p>

							<xf:submit submission="sbm-friends-friendfeed" appearance="minimal">
								<xf:label class="button73">
									OK
								</xf:label>
							</xf:submit>
						</xf:case>

						<xf:case id="view-friends-loaded">
							<div class="palette">
								<xf:repeat nodeset="instance('inst-friends')/subscription">
									<span class="item">
										<xf:output value="concat('&lt;img src=&quot;http://friendfeed.com/', nickname, '/picture?size=medium&quot; onerror=&quot;event.srcElement.src = &amp;quot;gadgets/friendfeed/default-user.png&amp;quot;;&quot; /&gt;')" class="avatar" />

										<xf:output value="concat('&lt;img id=&quot;friend-', nickname, '&quot; src=&quot;gadgets/common/images/button_fg.png&quot; srcDrag=&quot;http://friendfeed.com/', nickname, '/picture?size=medium&quot; alt=&quot;', name, '&quot; ondragstart=&quot;DRAGDROP.onDragStart(event);&quot; ondragend=&quot;DRAGDROP.onDragEnd(event);&quot; /&gt;')" class="avatar drag-proxy" />
									</span>
								</xf:repeat>

								<xf:repeat nodeset="instance('inst-friends')/list">
									<span class="item">
										<xf:output value="concat('&lt;img id=&quot;list-', nickname, '&quot; src=&quot;http://friendfeed.s3.amazonaws.com/pictures-', translate(id, '-', ''), '-medium.jpg&quot; alt=&quot;', name, '&quot; onerror=&quot;event.srcElement.src = &amp;quot;gadgets/friendfeed/default-list.png&amp;quot;;&quot; ondragstart=&quot;DRAGDROP.onDragStart(event);&quot; ondragend=&quot;DRAGDROP.onDragEnd(event);&quot; /&gt;')" class="avatar" />
									</span>
								</xf:repeat>
							</div>
						</xf:case>
					</xf:switch>
				</div>
			</xf:case>
		</xf:switch>

		<div class="stem">
			<img src="images/rose-16.png" alt="Hubbub" id="logo"/>

			<span class="hubs">
				<xf:repeat id="rpt-hubs" nodeset="instance('inst-hubbub')/xh:body/xh:div[@id = 'hubs']/*[contains(@typeof, 'hubbub:hub')]">
					<span class="hub-container">
						<xf:switch>
							<xf:case id="view-hubbase-trigger">
								<xf:trigger appearance="minimal" ondblclick="var evt = document.createEvent('Event'); evt.initEvent('hubbub-stem-dblclick', false, false); document.getElementById('mdl-gadgets').dispatchEvent(evt);">
									<xf:label class="hub-base">
										<xf:output ref="*[@property = 'hubbub:name']" />
									</xf:label>

									<xf:action ev:event="DOMActivate">
										<xf:setvalue ref="instance('inst-hub-base')" value="index('rpt-hubs')" />

										<xf:action if="*[@property = 'hubbub:visible'] = 'true'">
											<xf:setvalue bind="script-retval" value="js:EVENTS_send('backplane-animate', concat('hide|hub|', index('rpt-hubs')))" />

											<xf:setvalue ref="*[@property = 'hubbub:visible']/@pendingValue" value="'false'" />
										</xf:action>

										<xf:action if="*[@property = 'hubbub:visible'] = 'false'">
											<xf:setvalue bind="script-retval" value="js:EVENTS_send('backplane-animate', concat('show|hub|', index('rpt-hubs')))" />

											<xf:setvalue ref="*[@property = 'hubbub:visible']/@pendingValue" value="'true'" />
										</xf:action>

										<xf:action if="*[@property = 'hubbub:visible']/@pendingValue != ''">
											<xf:setvalue ref="*[@property = 'hubbub:visible']" value="@pendingValue" />

											<xf:setvalue ref="*[@property = 'hubbub:visible']/@pendingValue" value="''" />
										</xf:action>
									</xf:action>
								</xf:trigger>

								<xf:action ev:observer="mdl-gadgets" ev:event="hubbub-stem-dblclick">
									<xf:action if="number(instance('inst-hub-base')) = count(preceding-sibling::*[contains(@typeof, 'hubbub:hub')]) + 1">
										<xf:toggle case="view-hubbase-input" />
									</xf:action>
								</xf:action>

								<xf:trigger appearance="minimal">
									<xf:label class="close-button">
										<img src="gadgets/common/images/button_fg.png" alt="Delete this hub" class="button16" />
									</xf:label>

									<xf:action ev:event="DOMActivate">
										<xf:setvalue ref="js:EVENTS_send('hubbub-hub-delete-bubs', substring-after(@id, '-'), instance('inst-scripts')/retval)" value="'success'" />

										<xf:setvalue ref="js:EVENTS_send('hubbub-hub-close', substring-after(@id, '-'), instance('inst-scripts')/retval)" value="'success'" />

										<!--
											HACK: Simply invoking a delete of the context node here causes a crash (pure virtual function call)
											      in Ubiquity formsPlayer when the last hub is deleted. On debugging, it looks like the COM
											      reference counting has gone awry on the CXFormsElementButton instance for this trigger, which
											      results in an attempt to dereference a dangling pointer when CComPtrBase calls Release(). I
											      tried for a little while to fix the bug in the C++ source, but doing so proved beyond my
											      limited capabilities. Instead, I'm working round the issue by invoking the following actions
											      asynchronously using a javascript timer:
											          <xf:delete nodeset="." />

											          <xf:send submission="sbm-hubbub-save" />
										-->
										<xf:setvalue ref="instance('inst-delete-hub')/pending" value="index('rpt-hubs')" />

										<xf:setvalue bind="script-retval" value="js:TIMERS_setTimer(200, 'single', 'mdl-gadgets', 'hubbub-delete-hub', 'hubbub-delete-hub')" />
									</xf:action>
								</xf:trigger>
							</xf:case>

							<xf:case id="view-hubbase-input">
								<xf:input ref="*[@property = 'hubbub:name']">
									<xf:action ev:event="DOMActivate">
										<xf:toggle case="view-hubbase-trigger" />

										<xf:action if="../*[@property = 'hubbub:visible'] = 'false'">
											<xf:setvalue ref="../*[@property = 'hubbub:visible']" value="'true'" />

											<xf:setvalue bind="script-retval" value="js:EVENTS_send('backplane-animate', concat('show|hub|', index('rpt-hubs')))" />
										</xf:action>

										<xf:send submission="sbm-hubbub-save" />
									</xf:action>
								</xf:input>
							</xf:case>
						</xf:switch>
					</span>
				</xf:repeat>
			</span>

			<span class="newhub-button-container" id="newhub-button-container">
				<xf:trigger appearance="minimal" id="newhub-button">
					<xf:label class="newhub-button">
						<img src="gadgets/common/images/button_fg.png" alt="Create a new hub" class="button18" />
					</xf:label>

					<xf:action ev:event="DOMActivate">
						<xf:setvalue bind="script-retval" value="js:EVENTS_send('backplane-close', 'help|newhub')" />

						<xf:dispatch name="force-newhub-position-relative" target="mdl-gadgets" />

						<xf:dispatch name="hubbub-new-hub" target="mdl-gadgets" />

						<xf:setvalue ref="instance('inst-geometry')/x" value="js:GEOMETRY_getXPos('friends-button')" />

						<xf:setvalue ref="instance('inst-geometry')/width" value="js:GEOMETRY_getWidth('friends-button')" />

						<xf:setvalue bind="script-retval" value="js:EVENTS_send('backplane-open', concat('s,', floor(number(instance('inst-geometry')/x) + number(instance('inst-geometry')/width) div 2 - 9), ',c|help|friends'))" />
					</xf:action>
				</xf:trigger>
			</span>

			<span class="actions">
				<span class="events">
				</span>

				<xf:trigger appearance="minimal" id="feed-button">
					<xf:label class="feed-button">
						<img src="gadgets/common/images/button_fg.png" alt="View your home feed" class="button26" />
					</xf:label>

					<xf:action ev:event="DOMActivate">
						<xf:setvalue ref="instance('inst-geometry')/x" value="js:GEOMETRY_getXPos('feed-button')" />

						<xf:setvalue ref="instance('inst-geometry')/width" value="js:GEOMETRY_getWidth('feed-button')" />

						<xf:setvalue bind="script-retval" value="js:EVENTS_send('backplane-open', concat('s,', floor(number(instance('inst-geometry')/x) + number(instance('inst-geometry')/width) div 2 - 9), ',c|friendfeed.feed|__HUBBUB_USER_HOME'))" />
					</xf:action>
				</xf:trigger>

				<xf:trigger appearance="minimal" id="post-button">
					<xf:label class="post-button">
						<img src="gadgets/common/images/button_fg.png" alt="Update your Twitter status" class="button26" />
					</xf:label>

					<xf:action ev:event="DOMActivate">
						<xf:setvalue ref="instance('inst-geometry')/x" value="js:GEOMETRY_getXPos('post-button')" />

						<xf:setvalue ref="instance('inst-geometry')/width" value="js:GEOMETRY_getWidth('post-button')" />

						<xf:setvalue bind="script-retval" value="js:EVENTS_send('backplane-open', concat('s,', floor(number(instance('inst-geometry')/x) + number(instance('inst-geometry')/width) div 2 - 9), ',c|post|'))" />
					</xf:action>
				</xf:trigger>

				<xf:switch>
					<xf:case id="view-configure-show">
						<xf:trigger appearance="minimal" id="configure-button">
							<xf:label class="configure-button">
								<img src="gadgets/common/images/button_fg.png" alt="Show the configuration panel" class="button26" />
							</xf:label>

							<xf:action ev:event="DOMActivate">
								<xf:setvalue bind="script-retval" value="js:EVENTS_send('backplane-close', 'help|start')" />

								<xf:setvalue bind="script-retval" value="js:EVENTS_send('backplane-set-size', '|207')" />

								<xf:toggle case="view-config-authorisation" />

								<xf:toggle case="view-friends-show" />

								<xf:toggle case="view-configure-hide" />
							</xf:action>
						</xf:trigger>
					</xf:case>

					<xf:case id="view-configure-hide">
						<xf:trigger appearance="minimal">
							<xf:label class="configure-button">
								<img src="gadgets/common/images/button_fg.png" alt="Hide the configuration panel" class="button26" />
							</xf:label>

							<xf:action ev:event="DOMActivate">
								<xf:toggle case="view-configure-show" />

								<xf:toggle case="view-config-hidden" />

								<xf:setvalue bind="script-retval" value="js:EVENTS_send('backplane-set-size', '|26')" />
							</xf:action>
						</xf:trigger>
					</xf:case>
				</xf:switch>

				<xf:switch>
					<xf:case id="view-friends-show">
						<xf:trigger appearance="minimal" id="friends-button">
							<xf:label class="friends-button">
								<img src="gadgets/common/images/button_fg.png" alt="Show the friend palette" class="button26" />
							</xf:label>

							<xf:action ev:event="DOMActivate">
								<xf:setvalue bind="script-retval" value="js:EVENTS_send('backplane-close', 'help|friends')" />

								<xf:setvalue bind="script-retval" value="js:EVENTS_send('backplane-set-size', '|207')" />

								<xf:toggle case="view-config-friends" />

								<xf:toggle case="view-configure-show" />

								<xf:toggle case="view-friends-hide" />

								<xf:send submission="sbm-friends-friendfeed" />
							</xf:action>
						</xf:trigger>
					</xf:case>

					<xf:case id="view-friends-hide">
						<xf:trigger appearance="minimal" id="friends-button">
							<xf:label class="friends-button">
								<img src="gadgets/common/images/button_fg.png" alt="Hide the friend palette" class="button26" />
							</xf:label>

							<xf:action ev:event="DOMActivate">
								<xf:toggle case="view-friends-show" />

								<xf:toggle case="view-config-hidden" />

								<xf:setvalue bind="script-retval" value="js:EVENTS_send('backplane-set-size', '|26')" />
							</xf:action>
						</xf:trigger>
					</xf:case>
				</xf:switch>

				<xf:switch>
					<xf:case id="view-hide-hubbub">
						<xf:trigger appearance="minimal" id="hide-button">
							<xf:label class="hide-button">
								<img src="gadgets/common/images/button_fg.png" alt="Hide all Hubbub windows" class="button26" />
							</xf:label>

							<xf:dispatch ev:event="DOMActivate" name="hubbub-hide" target="mdl-gadgets" />
						</xf:trigger>
					</xf:case>

					<xf:case id="view-restore-hubbub">
						<xf:trigger appearance="minimal" id="restore-button">
							<xf:label class="restore-button">
								<img src="gadgets/common/images/button_fg.png" alt="Restore all Hubbub windows" class="button26" />
							</xf:label>

							<xf:action ev:event="DOMActivate">
								<xf:toggle case="view-hide-hubbub" />

								<xf:setvalue bind="script-retval" value="js:EVENTS_send('backplane-show-all')" />
							</xf:action>
						</xf:trigger>
					</xf:case>
				</xf:switch>

				<xf:trigger appearance="minimal" id="exit-button">
					<xf:label class="close-button">
						<img src="gadgets/common/images/button_fg.png" alt="Exit Hubbub" class="button16" />
					</xf:label>

					<xf:setvalue ev:event="DOMActivate" bind="script-retval" value="js:EVENTS_send('backplane-exit')" />
				</xf:trigger>
			</span>
		</div>
	</body>
</html>
